import QtQuick 1.0
import "common"


Item {
    id:root

    property int level : 0
    property string destPath : header.path
    property string activePath : ""

    signal returnClicked()
    signal taskClicked()


    Component.onCompleted: {
        systemModel.setDir("E:/cuteFtp");
        view.model.rootIndex = systemModel.pathIndex
    }

    Text {
        anchors.centerIn: parent
        font.pixelSize: 50
        text:"Local"
        opacity: 0.2
        color: "white"
    }



    Header {
        id:header
        onReturnClicked:view.model.rootIndex = view.model.parentModelIndex()
        path:systemModel.filePath(view.model.rootIndex)
        onTaskClicked:root.taskClicked()
    }


    ListView {
        id:view
        clip: true
        anchors.top: header.bottom
        width:root.width
        height: root.height - header.height
        enabled:!dialog.show
        model:VisualDataModel {
            id:visualModel
            model:systemModel

            delegate: OMenuItem {
                title: fileName
                subTitle: Qt.formatDateTime(lastModified,"dd MMM yyyy  hh:mm")
                fileSize:size
                icon:"image://icons/"+filePath
                active: root.activePath == filePath ? true : false
                onPressAndHold: {
                    dialog.fileName = fileName
                    dialog.path = filePath
                    dialog.show = true
                    view.currentIndex = index
                }


                onClicked:   {

                    if (model.hasModelChildren)
                        view.model.rootIndex = view.model.modelIndex(index)

                    else if ( ftpModel.state == 4){
                        startAnim()
                        ftpModel.uploadFile(filePath)

                    }
                }

            }
        }
    }


    BrowserDialog {
        id:dialog
        width: root.width
        height: root.height
        onOpened: console.debug(path)
        onRenamed:  systemModel.actionRename(visualModel.modelIndex(view.currentIndex), name)
        onMakeDir:  systemModel.actionMkdir(visualModel.modelIndex(view.currentIndex),name)
        onRemoved: systemModel.actionRemove(visualModel.modelIndex(view.currentIndex))

    }

}





